package com.tofindaway.hibernate.service;

import java.util.Random;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.tofindaway.hibernate.dao.SqlTableDao;
import com.tofindaway.hibernate.entity.SqlTable;

@Repository
public class TableDaoSpringTest {
	private SqlTableDao sqlTableDao;

	public SqlTableDao getSqlTableDao() {
		return sqlTableDao;
	}

	public void setSqlTableDao(SqlTableDao sqlTableDao) {
		this.sqlTableDao = sqlTableDao;
	}

	public void init() {
		Assert.notNull(sqlTableDao, "cannot be null!");
	}

	@Transactional
	public void test() {
		SqlTable sqlTable = sqlTableDao.findById(1000l);
		System.out.println(sqlTable);
		sqlTable.setNote("test" + new Random().nextInt(100));
		System.out.println(sqlTable);
	}

}
